package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.dao.ShopDeliveryDAO;
import com.junzhiit.nengji.model.ShopDelivery;
import com.junzhiit.nengji.model.enums.Is;

@Repository
public class ShopDeliveryDAOImpl extends AbstractBaseDAO<ShopDelivery> implements ShopDeliveryDAO {

	@Override
	public List<ShopDelivery> findAllByShopId(String shopId) {
		String sql = "select * from shop_delivery where shop_id = ? and is_delete = ? ";
		StatementParameter param = new StatementParameter();
		param.setString(shopId);
		param.setInt(Is.NO.toIntValue());
		return super.queryForList(sql, ShopDelivery.class, param);
	}

	@Override
	public ShopDelivery inspect(String shopId, Integer vehicle) {
		String sql = "select * from shop_delivery where shop_id = ? and vehicle =? and is_delete = ? ";
		StatementParameter param = new StatementParameter();
		param.setString(shopId);
		param.setInt(vehicle);
		param.setInt(Is.NO.toIntValue());
		return super.query(sql, ShopDelivery.class, param);
	}

	@Override
	public int getTotalCount(String shopId) {
		String sql = "select count(*) from shop_delivery where shop_id = ?  and is_delete = ? ";
		StatementParameter param = new StatementParameter();
		param.setString(shopId);
		param.setInt(Is.NO.toIntValue());
		return super.queryForInt(sql, param);
	}

	@Override
	public ShopDelivery adapt(String shopId, Integer type, Integer vehicle) {
		String sql = "select * from shop_delivery where shop_id=? and type=? and vehicle = ? order by max_delivery desc limit 0,1";
		StatementParameter param = new StatementParameter();
		param.setString(shopId);
		param.setInt(type);
		param.setInt(vehicle);
		return super.query(sql, ShopDelivery.class, param);
	}

}
